package com.example.football.controller;

import com.example.football.pojo.People;
import com.example.football.pojo.Schedule;
import com.example.football.service.ScheduleService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.List;

@Controller
public class ScheduleController {
    @Resource
    private ScheduleService cc;

    @RequestMapping("schedulelist")
    public String queryAll(Model model) {
        List<Schedule> list = cc.queryAll();
        //存入model
        model.addAttribute("list", list);
        //控制跳转

        return "schedulelist";
    }

    @PostMapping("findByTeam")
    public String findByTeam(String team,Model model){
        List<Schedule> list = cc.queryByTeam(team);
        //存入model
        model.addAttribute("list", list);
        return "schedulelist";
    }

    @RequestMapping("removeBySchedule")
    public String removeBySchedule(Integer id) {
        try {
            cc.removeBySchedule(id);
            return "redirect:/schedulelist";
        } catch (Exception e) {
            return "error";
        }
    }

    @GetMapping("findById1")
    public String findById(Integer id, Model model){
        Schedule list = cc.queryById(id);
        //存入model
        model.addAttribute("list", list);
        return "updateschedule";
    }

    //数据修改
    @PostMapping("updateSchedule")
    public String changeSchedule(Schedule schedule) {
        try {
            cc.changeSchedule(schedule);
            return "redirect:/schedulelist";
        } catch (Exception e) {
            return "error";
        }
    }

    @RequestMapping("addSchedulePage")
    public String addSchedulePage() {
        return "addschedule";
    }

    @RequestMapping("addSchedule")
    public String addSchedule(Schedule schedule) {
        try {
            cc.addSchedule(schedule);
            return "redirect:/schedulelist";
        } catch (Exception e) {
            e.printStackTrace();
            return "error";
        }
    }
}
